from __future__ import unicode_literals

from django.db import models
import json

# Create your models here.


class User(models.Model):
    # CHOICE_COLLEGE = ('WHU', 'HUST')
    # with open('data.json', 'r') as collegeMessage:
    #     data = json.load(collegeMessage, 'utf-8')

    email = models.EmailField(primary_key=True)
    username = models.CharField(max_length=254)
    password = models.CharField(max_length=254)
    college = models.CharField(max_length=62)
    school = models.CharField(max_length=62)
    qq = models.CharField(max_length=15)
    user_token = models.OneToOneField('Token', default=None)

    def set_password(self, password):
        self.password = password

    def set_token(self, token):
        self.user_token = token


class Token(models.Model):
    token_id = models.AutoField(primary_key=True)
    token = models.CharField(max_length=40, unique=True)
    refresh_token = models.CharField(max_length=40, unique=True)
    expire_time = models.DateTimeField()


class BookList(models.Model):
    book_list_id = models.AutoField(primary_key=True)
    slug = models.SlugField()
    owner = models.ForeignKey(User, on_delete=True)


class Book(models.Model):
    book_id = models.AutoField(primary_key=True)
    book_name = models.CharField(max_length=200)
    price = models.FloatField()
    publisher = models.CharField(max_length=400, null=True, blank=True)
    book_list = models.ForeignKey(BookList, on_delete=True)